import { defineComponent, ref, watch, openBlock, createBlock, unref, mergeProps, withCtx, createElementVNode, renderSlot, createElementBlock, Fragment, renderList, normalizeClass, normalizeStyle, toDisplayString, createCommentVNode, createVNode, createTextVNode } from "vue";
import { Popup } from "../popup/index.mjs";
import { Skeleton, Button } from "ant-design-vue";
import { TreeSearch } from "../tree-search/index.mjs";
import "./select-member-list.vue.mjs";
import "./select-member-item.vue.mjs";
import { Empty } from "../empty/index.mjs";
import _sfc_main$1 from "./select-member-list.vue2.mjs";
import _sfc_main$2 from "./select-member-item.vue2.mjs";
const _hoisted_1 = { class: "me-select-member" };
const _hoisted_2 = { class: "me-select-member-content" };
const _hoisted_3 = { class: "me-select-member-inner" };
const _hoisted_4 = { class: "me-select-member-header" };
const _hoisted_5 = {
  key: 0,
  class: "me-select-member-body"
};
const _hoisted_6 = {
  key: 1,
  class: "me-select-member-body"
};
const _hoisted_7 = {
  key: 2,
  class: "me-select-member-body"
};
const _hoisted_8 = { class: "me-select-member-bottom" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...{
    name: "me-select-member"
  },
  __name: "select-member",
  props: {
    show: { type: Boolean, default: false },
    columns: { default() {
      return [];
    } },
    selectedList: { default() {
      return [];
    } },
    popup: { default() {
      return {
        title: "选择成员",
        width: "1200px",
        height: "600px",
        mask: true,
        draggable: true
      };
    } }
  },
  emits: ["close", "select-tree-node", "select-list-node", "select-member", "confirm", "cancel", "update:show"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const visible = ref(false);
    const selectedList = ref([]);
    const prevSelectedList = ref([]);
    watch(() => props.show, () => {
      if (props.show) {
        visible.value = true;
        selectedList.value = JSON.parse(JSON.stringify(props.selectedList));
        prevSelectedList.value = JSON.parse(JSON.stringify(props.selectedList));
      } else {
        visible.value = false;
      }
    });
    watch(() => props.selectedList, () => {
      selectedList.value = props.selectedList;
    });
    const onClose = () => {
      visible.value = false;
      emits("update:show", false);
      emits("close");
    };
    const onSelect = (node) => {
      emits("select-list-node", node);
    };
    const onSelectTreeNode = (selectedKeys, evt) => {
      emits("select-tree-node", selectedKeys, evt);
    };
    const onSelectMember = (member) => {
      if (member.memberSelected) {
        selectedList.value.push(member);
      } else {
        selectedList.value = selectedList.value.filter((item) => item.value !== member.value);
      }
      emits("select-member", selectedList.value);
    };
    const onDeleteMember = (member) => {
      selectedList.value = selectedList.value.filter((item) => item.value !== member.value);
      emits("select-member", selectedList.value);
    };
    const onCancel = () => {
      selectedList.value = JSON.parse(JSON.stringify(prevSelectedList.value));
      visible.value = false;
      emits("cancel");
      emits("update:show", false);
    };
    const onConfirm = () => {
      visible.value = false;
      emits("confirm", selectedList.value);
      emits("update:show", false);
    };
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(Popup), mergeProps({
        value: visible.value,
        "onUpdate:value": _cache[0] || (_cache[0] = ($event) => visible.value = $event)
      }, _ctx.popup, { onClose }), {
        default: withCtx(() => [
          createElementVNode("div", _hoisted_1, [
            renderSlot(_ctx.$slots, "top"),
            createElementVNode("div", _hoisted_2, [
              (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.columns, (column, index) => {
                return openBlock(), createElementBlock("div", {
                  key: index,
                  class: normalizeClass(["me-select-member-item", [column.width ? "me-select-member-item-width" : ""]]),
                  style: normalizeStyle({ width: column.width })
                }, [
                  createElementVNode("div", _hoisted_3, [
                    renderSlot(_ctx.$slots, "header", {
                      column,
                      index
                    }, () => [
                      createElementVNode("div", _hoisted_4, toDisplayString(column.title), 1)
                    ]),
                    renderSlot(_ctx.$slots, "body", {
                      column,
                      index
                    }, () => [
                      index === 0 ? (openBlock(), createElementBlock("div", _hoisted_5, [
                        column.loading ? (openBlock(), createBlock(unref(Skeleton), {
                          key: 0,
                          active: "",
                          paragraph: { rows: 15, width: "100%" },
                          title: false
                        })) : (openBlock(), createBlock(unref(TreeSearch), {
                          key: 1,
                          onSelect,
                          "show-list": "",
                          "tree-props": column.dataSource,
                          "tree-events": { select: onSelectTreeNode }
                        }, null, 8, ["tree-props", "tree-events"]))
                      ])) : createCommentVNode("", true),
                      index === 1 ? (openBlock(), createElementBlock("div", _hoisted_6, [
                        column.loading ? (openBlock(), createBlock(unref(Skeleton), {
                          key: 0,
                          active: "",
                          paragraph: { rows: 15, width: "100%" },
                          title: false
                        })) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
                          Array.isArray(column.dataSource) && column.dataSource.length > 0 ? (openBlock(), createBlock(_sfc_main$1, {
                            key: 0,
                            "selected-member-list": selectedList.value,
                            "member-list": column.dataSource,
                            onClick: onSelectMember
                          }, {
                            member: withCtx(({ member }) => [
                              renderSlot(_ctx.$slots, "member", { member })
                            ]),
                            _: 2
                          }, 1032, ["selected-member-list", "member-list"])) : Array.isArray(column.dataSource) && column.dataSource.length === 0 ? (openBlock(), createBlock(unref(Empty), {
                            key: 1,
                            description: "暂无数据"
                          })) : createCommentVNode("", true)
                        ], 64))
                      ])) : createCommentVNode("", true),
                      index === 2 ? (openBlock(), createElementBlock("div", _hoisted_7, [
                        column.loading ? (openBlock(), createBlock(unref(Skeleton), {
                          key: 0,
                          active: "",
                          paragraph: { rows: 15, width: "100%" },
                          title: false
                        })) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
                          selectedList.value.length > 0 ? (openBlock(), createBlock(_sfc_main$2, {
                            key: 0,
                            "data-source": selectedList.value,
                            onDelete: onDeleteMember
                          }, {
                            "select-member": withCtx(({ member }) => [
                              renderSlot(_ctx.$slots, "select-member", { member })
                            ]),
                            _: 3
                          }, 8, ["data-source"])) : (openBlock(), createBlock(unref(Empty), {
                            key: 1,
                            description: "暂无数据"
                          }))
                        ], 64))
                      ])) : createCommentVNode("", true)
                    ]),
                    renderSlot(_ctx.$slots, "footer", {
                      column,
                      index
                    })
                  ])
                ], 6);
              }), 128))
            ]),
            renderSlot(_ctx.$slots, "bottom", {}, () => [
              createElementVNode("div", _hoisted_8, [
                createVNode(unref(Button), {
                  onClick: onCancel,
                  class: "me-select-member-bottom-btn"
                }, {
                  default: withCtx(() => _cache[1] || (_cache[1] = [
                    createTextVNode("取消")
                  ])),
                  _: 1
                }),
                createVNode(unref(Button), {
                  onClick: onConfirm,
                  type: "primary",
                  class: "me-select-member-bottom-btn"
                }, {
                  default: withCtx(() => _cache[2] || (_cache[2] = [
                    createTextVNode("确定")
                  ])),
                  _: 1
                })
              ])
            ])
          ])
        ]),
        _: 3
      }, 16, ["value"]);
    };
  }
});
export {
  _sfc_main as default
};
//# sourceMappingURL=select-member.vue2.mjs.map
